<template>
  <div class="main">
    <section class="header">
      <div class="header-main">
        <div class="header-img-container">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </div>
        <div class="header-info">
          <div style="font-size:14px">{{ user.level | job }}</div>
          <div style="font-size:28px"> {{ user.name }}</div>
          <div style="font-size:14px">UID: {{ user.uid }}</div>
        </div>
        <div>

        </div>
      </div>
    </section>
    <section class="middle">
      <div class="menu">
        <!--        <div :class="{ 'menu-btn-active': btn_isActive_myupload, 'menu-btn': true }" @click="bthChange('MyVideo')" v-if="user.level == 1" >视频-->
        <!--        </div>-->
        <!--        <div :class="{ 'menu-btn-active': btn_isActive_myupload, 'menu-btn': true }" @click="bthChange('MyFile')" v-if="user.level == 1">文件-->
        <!--        </div>-->
        <div :class="{ 'menu-btn-active': btn_isActive_myupload, 'menu-btn': true }" @click="bthChange('MyArticles')">
          文章
        </div>
        <div :class="{ 'menu-btn-active': btn_isActive_myupload, 'menu-btn': true }" @click="bthChange('MyPaperTea')" v-if="user.level == 1">
          习题
        </div>
        <div :class="{ 'menu-btn-active': btn_isActive_myupload, 'menu-btn': true }" @click="bthChange('MyPaperStu')"
             v-if="user.level == 2">
          答题记录
        </div>
      </div>
      <div class="show-option">
        <transition name="into" appear mode="out-in">
          <component :is="componentId" :btnVisible="btnVisible" :verifyUser="userId"></component>
        </transition>
      </div>
    </section>
  </div>
</template>

<script>
import MyArticles from "@/components/MyArticles.vue";
import MyVideo from "@/components/MyVideo.vue";
import MyFile from "@/components/MyFile.vue";
import MyPaperStu from "@/components/MyPaperStu";
import MyPaperTea from "@/components/MyPaperTea";

export default {
  name: "Mine",
  components: {
    MyVideo,
    MyFile,
    MyArticles,
    MyPaperTea,
    MyPaperStu
  },
  data() {
    return {
      level: false,
      btn_isActive_myupload: false,
      componentId: "",
      btnVisible: true,
      user: {},
      imageUrl: '',
      userId: this.$route.query.userId,
    }
  },
  watch: {
    isLogin() {
      this.btnVisible = this.isLogin;
    }
  },
  methods: {
    changeImg() {
      this.$axios.post("user/changeImg", this.$qs.stringify({id: this.user.id, imageUrl: this.imageUrl}))
          .then(resp => {
            let res = resp.data
            this.user.imageUrl = this.imageUrl;
          })
          .catch(error => {
            console.log(error)
          })
    },
    bthChange(com) {
      this.componentId = com
    },
    getUser() {
      let id = this.userId;
      this.$axios.get("user/searchUserById?id=" + id)
          .then(resp => {
            let res = resp.data
            this.user = res.data;
            this.imageUrl = this.user.imageUrl;
          })
          .catch(error => {
            console.log(error)
          })
    },
    setImg() {
      if (this.imageUrl == null) {
        this.imageUrl = 'https://kotokawa-akira-mywife.site/web/api/account/getProfile/000'
      }
    },
    showMessage(message) {
      this.$notify({
        title: '消息',
        message: message,
        type: 'success',
        duration: 2000
      });
    }
  },
  filters: {
    job: function (value) {
      if (value == 1) {
        return "教师"
      } else {
        return "学生"
      }
    }
  },
  mounted() {
    console.log("userId")
    console.log(this.userId)
    this.btnVisible = this.isLogin;
    this.getUser()
    this.setImg();
  }
}
</script>

<style lang="css">
.into-enter-active,
.into-leave-active {
  transition: all .3s ease;
}

.into-enter-from {
  opacity: 0.0;
  transform: translate(0, 50px);
}

.into-enter-to {
  opacity: 1.0;
  transform: translate(0, 0);
}

.into-leave-to {
  opacity: 0.0;
  transform: translate(0, 0);
}

.into-leave-from {
  opacity: 1.0;
  transform: translate(0, 0);
}

.main {
  width: 80%;
  margin: 0 auto;
}

.header {
  width: 100%;
  aspect-ratio: 6/1;
  background-image: url('~@/assets/image.png');
  background-repeat: no-repeat;
  background-position: left -450px;
  display: flex;
  align-items: flex-end;
}

.header-img-container {
  width: 80px;
  height: 80px;
  border-radius: 40px;
  overflow: hidden;
}

.header-img-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-upload {
  width: 100%;
  height: 100%;
}

.header-main {
  min-width: 200px;
  width: 500px;
  height: 100px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.header-info {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
  height: 75%;
  color: #fff;
}

.header-info div:nth-child(1) {
  max-width: 300px;
}

.middle {
  width: 100%;
  height: auto;
  margin: 0 auto;
  padding: 20px 0px 20px 0px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.menu {
  width: 15%;
  box-sizing: border-box;
  background-color: #fff;
  padding: 10px 10px 10px 10px;
  user-select: none;
}

.menu-btn {
  margin: 5px 0 5px 0;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.0);
  font-size: 20px;
  cursor: pointer;
  transition: all .3s ease;
  padding: 5px 5px 5px 5px;
}

.menu-btn:hover {
  color: #888888;
  border: 1px solid;
}

.menu-btn-active {
  color: #888888;
  border: 1px solid;
}

.show-option {
  width: 85%;
  margin: 0 0 0 10px;
  box-sizing: border-box;
  background: #fff;
}

.el-upload {
  width: 100% !important;
  height: 100% !important;
}

.el-image {
  width: 100% !important;
  height: 100% !important;
}

.el-image__wrapper {
  width: 100% !important;
  height: 100% !important;
}

.change-btn {
  border-radius: 6px;
  border: 1px solid #fff;
  background-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  transition: all .3s ease;
  user-select: none;
  padding: 0 5px 0 5px;
}

.change-btn:nth-child(1) {
  margin-bottom: 10px;
}

.change-btn:hover {
  color: #888888;
  border: 1px solid;
  background-color: rgba(154, 200, 226, 0.2);
}

@media screen and (max-width: 550px) {
  .main {
    width: 100%;
  }

  .middle {
    flex-direction: column;
    justify-content: flex-start;
  }

  .menu {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
  }

  .show-option {
    width: 100%;
    padding: 0;
  }

  .item-time {
    font-size: 14px !important;
  }

  .el-message-box {
    width: 80% !important
  }

  .header-info div:nth-child(1) {
    max-width: 150px;
  }

  .show-option {
    margin: 0;
    padding: 0 0 0 10px;
  }
}
</style>